var app = getApp();
var that;

var qin = require("../../utils/qin.js");
var qqmap = require("../../utils/qqmap.js");
var WxParse = require("../../wxParse/wxParse.js");
var qqmapsdk;
Page({
  data: {
    item: "",
    thumbimg: "",
    postCode: "",
    tel: "",
    routers: [
      {
        name: 'T1',
        url: '',
        icon: '../../效果图/1.png'
      },
      {
        name: 'T2',
        url: '',
        icon: '../../效果图/1.png'
      },
      {
        name: 'T3',
        url: '',
        icon: '../../效果图/1.png'
      },
      {
        name: 'T4',
        url: '',
        icon: '../../效果图/1.png'
      },
      {
        name: 'T5',
        url: '',
        icon: '../../效果图/1.png'
      },
      {
        name: 'T6',
        url: '',
        icon: '../../效果图/1.png'
      },
      {
        name: 'T7',
        url: '',
        icon: '../../效果图/1.png'
      },
      {
        name: 'T8',
        url: '',
        icon: '../../效果图/1.png'
      },
      {
        name: 'T9',
        url: '',
        icon: '../../效果图/1.png'
      }
    ],
    currentTab: 0,
    // navbar: ["简要信息", "详细介绍"],
    shownavigation: true
  },
  onNavbarTap: function (ev) {
    this.setData({
      currentTab: ev.currentTarget.dataset.index
    })
  },
  toAddress: function (ev) {
    wx.openLocation({
      latitude: parseFloat(ev.currentTarget.dataset.latitude),
      longitude: parseFloat(ev.currentTarget.dataset.longitude),
      scale: 28,
      name: ev.currentTarget.dataset.title
    })
  },
  callTel: function (ev) {
    wx.makePhoneCall({
      phoneNumber: ev.currentTarget.dataset.tel
    })
  },
  callMobile: function (ev) {
    wx.makePhoneCall({
      phoneNumber: ev.currentTarget.dataset.mobile
    })
  },
  onLoad: function (res) {
    that = this;
    qin.getCompany("openid",
      function (res) {
        if (0 == res.data.errno) {
          var showTel = "";
          var tel = res.data.item.tel;
          var postCode = res.data.item.post_code;
          if (postCode) {
            showTel = "0" + postCode + "-" + tel;
            tel = "0" + postCode + tel
          }
          var thumbimg = "";
          if (res.data.item.thumbimg && !/^http/i.test(res.data.item.thumbimg)) {
            thumbimg = qin.website + res.data.item.thumbimg
          }
          wx.setNavigationBarTitle({
            title: "保定新梦想网络科技有限公司"
          });
          WxParse.wxParse("article", "html", res.data.item.content, that, 2);
          var showNavigation = true;
          if (0 == res.data.item.use_navigation) {
            showNavigation = false
          }
          that.setData({
            item: res.data.item,
            showTel: showTel,
            tel: tel,
            thumbimg: thumbimg,
            showNavigation: showNavigation
          })
        }
      })
  }
});